// Loesung_von_Aufgabe_7.6_4_Orbitalmodell

// H-Atom Orbitalmodell für n = 2, l = 1, m = 0

int a = 200; // Anzahl der Spalten
int b = 200; // Anzahl der Zeilen
int c = 200; // Anzahl der z-Werte

float x;
float y;
float z;

float wy;
float r = 100;
float n = 10;

void setup()
{
  // P3D erlaubt die dreidimensionale Darstellung
  size(900, 900, P3D);
}

void draw()
{
  background(0);

  // Verschiebung des Koordinatenursprungs
  translate(450, 450);

  // Rotation um die x- und y-Achse
  rotateX(0.008*mouseY);
  rotateY(0.008*mouseX);

  // Atomkern wird gezeichnet
  noStroke();
  fill(255, 0, 0);
  sphere(10);

  // Berechnung der Aufenthaltsorte für die Elektronen
  for (int i = 0; i < a; i = i + 10)
  {
    for (int j = 0; j < b; j = j + 10)
    {
      for (int k = 0; k < c; k = k + 10)
      {
        x = 30 * randomGaussian() + i - 100;
        y = 30 * randomGaussian() + j + 50;
        z = 30 * randomGaussian() + k - 100;

        stroke(255, 0, 0); 
        strokeWeight(3);
        point(x, y+100, z+30);

        x = 30 * randomGaussian() - i + 100;
        y = 30 * randomGaussian() - j - 50;
        z = 30 * randomGaussian() - k + 100;

        // Die Aufenthaltsorte des Elektrons werden gezeichnet
        stroke(255, 255, 0); 
        strokeWeight(3);
        point(x, y-100, z-30);
      }
    }
  }

  // Der Torus wird gezeichnet
  for (float w = 0; w <= 500; w = w + 0.1)
  {
    /* Eine kreisförmige Fläche, die sich rechts vom Ursprung 
     befindet, wird per Zufallsgenerator mit Punkten gefüllt */
    x = r * sin(w/n);
    y = r * cos(w/n);

    stroke(255);
    strokeWeight(3);
    point(200+40*randomGaussian(), 40*randomGaussian());

    // Der Kreis rotiert um die y-Achse
    wy = wy + 0.1;
    rotateY(wy);
  }
}